<template>
	<view>
		<uni-nav-bar left-icon="left" left-text="返回" @clickLeft="go" height="140rpx"  title="添加车辆" />
		<view class="">
			<image src="../../../static/img/che.png" mode=""></image>
		</view>
		<view class="cu-form-group">
		    <input placeholder="" disabled="true" @tap="plateShow=true" v-model.trim="plateNo" />
		    <plate-input v-if="plateShow" :plate="plateNo" @export="setPlate" @close="plateShow=false" />
		</view>
		<button @tap="addcar">添加</button>
	</view>
   
</template>

<script>
    import plateInput from '@/components/uni-plate-input/uni-plate-input.vue'
	import Index from '@/apis/index.js'
    export default {
        components: {
            plateInput
        },
        data() {
            return {
                plateNo:'',
                plateShow:false
            }
        },
		onLoad() {
			
		},
        methods: {
            setPlate(plate){
                if(plate.length >= 7) this.plateNo = plate
                this.plateShow = false
            },
			async addcar(){
				let data = {
					carno:this.plateNo
				}
				let res = await Index.usercaradd(data)
				if(this.plateNo==""){
					uni.showToast({
						title: '请先选择车牌号'
					});
				}else{
					if(res.errCode==10000){
						uni.showToast({
							title: '添加成功'
						});
						uni.navigateTo({
							url:'/pages/My/Vehicle/AddVehicle/AddVehicle'
						})
					}
				}
			},
			go(){
				uni.navigateTo({
					url:'/pages/My/My'
				})
			}
        }
    }
</script>

<style lang="less">
	@import url('@/static/css/my/vehicle/vehicle.css');
</style>
